const Koa  = require('koa')
const serve = require('koa-static');
const { historyApiFallback } = require('koa2-connect-history-api-fallback')
const proxy = require('koa2-proxy-middleware')

const app = new Koa();
// 处理history模式导致没有#号, 刷新404问题
app.use(historyApiFallback())

// api 数据代理服务
app.use(proxy({
    targets: {
      // 跟浏览器约定的api转发标记
      '/loveyou/(.*)': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        pathRewrite: {
            // 转发到后端前, 跟后端约定的 api 地址
            '/loveyou': '/api'
          }
      }
    }
  }))

app.use(serve(__dirname + "/public")); //将public下的代码静态化
app.listen(3333, () => {
     console.log('人资项目启动')
     console.log('http://localhost:3333/');
})